package 剑指offer_leetcode;

/**
 * JZ25合并两个排序的链表
 */
public class 剑指Offer25_合并两个排序的链表 {
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode res = new ListNode(0);
        ListNode l3 = res;
        while(l1!=null && l2!=null){
            if(l1.val<=l2.val){
                l3.next = l1;
                l1 = l1.next;
                l3 = l3.next;
            }else{
                l3.next = l2;
                l3 = l3.next;
                l2 = l2.next;
            }
        }
        l3.next = l1!=null?l1:l2;
        return res.next;
    }
}
